﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ResourceManager
{
	Dictionary<string,Object> prefabMap;

	public Object Load(string strPath)
	{
		if (prefabMap == null) 
		{
			prefabMap = new Dictionary<string, Object> ();
		}

		Object obj = null;
		if (!prefabMap.TryGetValue(strPath,out obj)) 
		{
			obj = Resources.Load (strPath);
		    prefabMap.Add (strPath, obj as Object);
		}

		return obj;
	}

	public bool HasLoad(string strPath)
	{
		if (prefabMap == null)
			return false;

		return prefabMap.ContainsKey(strPath);
	}

	public Object Get(string strPath)
	{
		DebugUtil.Assert(prefabMap != null);
		DebugUtil.Assert(prefabMap.ContainsKey(strPath));
		return prefabMap[strPath];
	}

	public void UnLoad (string strPath)
	{
		DebugUtil.Assert(prefabMap != null);
		prefabMap.Remove(strPath);
	}
}
